package com.xbongbong.paas.pojo.dto;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.QueryIgnore;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.pro.formdata.pojo.SaasNeedRedundantAttrPojo;
import com.xbongbong.pro.user.pojo.ReturnUserAndDepartmentPojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @author: wufeng
 * @date: 2018/9/6 15:24
 * @desrcption: 保存表单数据
 */
@Getter
@Setter
@ToString
public class FormDataUpdateDTO extends BaseDTO {

    private static final long serialVersionUID = 890245517899327058L;

    @NotNull(message = "{dto.msg.formDataUpdateBatch.formId.NotNull}")
    private Long formId;

    @NotNull(message = "{dto.msg.formExplainList.appId.NotNull}")
    private Long appId;

    @NotNull(message = "{dto.msg.formDataUpdateGet.menuId.NotNull}")
    @Getter(onMethod_ = {@QueryIgnore})
    private Long menuId;

    @NotNull(message = "{dto.msg.formDataOwner.formDataId.NotNull}")
    private Long dataId;

    // TODO 更新时是否能编辑流水号
    /**
     * 编号，流水号
     * TODO 更新时是否能编辑流水号
     */
    @Length(max = 50, message = "{dto.msg.formDataAdd.serialNo.Length}")
    private String serialNo;
    /**
     * 负责人
     */
    private List<ReturnUserAndDepartmentPojo> ownerId;
    /**
     * 协同人
     */
    private List<ReturnUserAndDepartmentPojo> coUserId;
    /**
     * 可见部门集合
     */
    private List<Object> visbleDept;
    /**
     * 可见人集合
     */
    private List<Object> visbleUser;
    /**
     * 所属部门
     */
    private Long departmentId;

    /**
     *  2020/4/21 13:51 API TEST ERROR 26576
     */
    @NotEmpty(message = "表单数据不能为空")
    private JSONObject dataList;

    /**
     * saas标记
     * TODO  后面应该限制非空
     */
    private Integer saasMark;
    /**
     * saas业务类型
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer businessType;
    /**
     * saas子业务类型
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer subBusinessType;

    /**
     * saas所需的特殊传参pojo
     */
    private SaasNeedRedundantAttrPojo saasNeedRedundantAttrPoJo;

    /**
     * 是否是导入
     */
    private Integer isImport;
    /**
     * 字段容器
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Map<String, FieldAttrEntity> explainMap;
    /**
     * 流程创建人id
     */
    private String processCreatorId;

    /**
     * 资金管理中 金额明细详情
     */
    private JSONArray amountDetail;
    /**
     * 是否是覆盖导入
     */
    private Integer isCover;
    /**
     * 是否来自审批
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Integer isFromProcess;

    /**
     * 是否符合触发条件
     */
    private Boolean isSatisfyTrigger = false;
    /**
     * 符合触发类型的list
     * 类型WorkflowEntity 引不到
     */
    private List workflowEntityList;

    /**
     * 团队需审批字段是否编辑了
     */
    private Boolean teamIsEdit = false;

    // 线索转换新建客户时，会传这个线索的id和是否将线索跟进记录带到客户的标识
    private Long clueId;
    private Integer isBringCustomer;
    // 审批状态 用于区分是否重新提交
    private Integer taskType;

    //审批提交人id
    private String commitUserId;

    /**
     * 部分字段导入
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private List<String> attrList;

    /**
     * 返回子表单给上一层方法调用
     */
    private JSONObject subFormData;

    public FormDataUpdateDTO() {
        saasNeedRedundantAttrPoJo = new SaasNeedRedundantAttrPojo();
        isImport = 0;
    }


    public FormDataUpdateDTO(Long formId, Long appId, Long menuId, Long dataId, JSONObject dataList, Integer saasMark, Integer businessType,
                             Integer subBusinessType, SaasNeedRedundantAttrPojo saasNeedRedundantAttrPoJo, UserVO userVO, String corpid, String httpHeader, String platform) {
        this.formId = formId;
        this.appId = appId;
        this.menuId = menuId;
        this.dataId = dataId;
        this.dataList = dataList;
        this.saasMark = saasMark;
        this.businessType = businessType;
        this.subBusinessType = subBusinessType;
        this.saasNeedRedundantAttrPoJo = saasNeedRedundantAttrPoJo;
        setLoginUser(userVO);
        setCorpid(corpid);
        setLoginUserName(userVO.getName());
        setUserId(userVO.getUserId());
        setHttpHeader(httpHeader);
        setPlatform(platform);
    }

    public FormDataUpdateDTO(Long dataId, String corpid, Long formId, Integer businessType, Integer saasMark){
        this.dataId = dataId;
        this.formId = formId;
        this.businessType = businessType;
        this.saasMark = saasMark;
        setCorpid(corpid);
    }
}
